{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "from concurrent.futures import ThreadPoolExecutor\n",
    "def returnnumber(a):\n",
    "    time.sleep(1)\n",
    "    return a\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "returnnumber(12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Count: 0\n",
      "Count: 1\n",
      "Count: 2\n",
      "Count: 3\n",
      "Count: 4\n",
      "Count: 5\n",
      "Count: 6\n",
      "Count: 7\n",
      "Count: 8\n",
      "Count: 9\n",
      "Count: 10\n",
      "Count: 11\n",
      "Count: 12\n",
      "Count: 13\n",
      "Count: 14\n",
      "Count: 15\n",
      "Count: 16\n",
      "Count: 17\n",
      "Count: 18\n",
      "Count: 19\n",
      "Count: 20\n",
      "Count: 21\n",
      "Count: 22\n",
      "Count: 23\n",
      "Count: 24\n",
      "Count: 25\n",
      "Count: 26\n",
      "Count: 27\n",
      "Count: 28\n",
      "Count: 29\n",
      "Count: 30\n",
      "Count: 31\n",
      "Count: 32\n",
      "Count: 33\n",
      "Count: 34\n",
      "Count: 35\n",
      "Count: 36\n",
      "Count: 37\n",
      "Count: 38\n",
      "Count: 39\n",
      "Count: 40\n",
      "Count: 41\n",
      "Count: 42\n",
      "Count: 43\n",
      "Count: 44\n",
      "Count: 45\n",
      "Count: 46\n",
      "Count: 47\n",
      "Count: 48\n",
      "Count: 49\n",
      "Count: 50\n",
      "Count: 51\n",
      "Count: 52\n",
      "Count: 53\n",
      "Count: 54\n",
      "Count: 55\n",
      "Count: 56\n",
      "Count: 57\n",
      "Count: 58\n",
      "Count: 59\n",
      "Count: 60\n",
      "Count: 61\n",
      "Count: 62\n",
      "Count: 63\n",
      "Count: 64\n",
      "Count: 65\n",
      "Count: 66\n",
      "Count: 67\n",
      "Count: 68\n",
      "Count: 69\n",
      "Count: 70\n",
      "Count: 71\n",
      "Count: 72\n",
      "Count: 73\n",
      "Count: 74\n",
      "Count: 75\n",
      "Count: 76\n",
      "Count: 77\n",
      "Count: 78\n",
      "Count: 79\n",
      "Count: 80\n",
      "Count: 81\n",
      "Count: 82\n",
      "Count: 83\n",
      "Count: 84\n",
      "Count: 85\n",
      "Count: 86\n",
      "Count: 87\n",
      "Count: 88\n",
      "Count: 89\n",
      "Count: 90\n",
      "Count: 91\n",
      "Count: 92\n",
      "Count: 93\n",
      "Count: 94\n",
      "Count: 95\n",
      "Count: 96\n",
      "Count: 97\n",
      "Count: 98\n",
      "Count: 99\n",
      "The total time is :34.19570589065552\n"
     ]
    }
   ],
   "source": [
    "start=time.time()\n",
    "with ThreadPoolExecutor(max_workers=3) as executor:\n",
    "    for result in executor.map(returnnumber,range(100)):\n",
    "        print(\"Count: {0}\".format(result))\n",
    "print(\"The total time is :{0}\".format(time.time()-start))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
